<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>员工管理</title>
<meta name="viewport" content="width=100%, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/lib/weix/style/weui.min.css">
<link rel="stylesheet" href="/css/fonts.css">
<link rel="stylesheet" href="/css/comm.css">
<link rel="stylesheet" href="/css/list_user.css">
</head>

<body>
<div class="weui-search-bar" id="searchBar">
    <form class="weui-search-bar__form">
        <div class="weui-search-bar__box">
            <i class="weui-icon-search"></i>
            <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required>
            <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
        </div>
        <label class="weui-search-bar__label" id="searchText">
            <i class="weui-icon-search"></i>
            <span>搜索</span>
        </label>
    </form>
    <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
</div>

<div class="weui-cells">
    <a style="display:none;" id="J_tianj" class="weui-cell weui-cell_access" href="/userPage/adduser?topen=2">
        <div class="weui-cell__hd tbs"><i class="icon-user"></i></div>
        <div class="weui-cell__bd">
            <p>添加员工</p>
        </div>
    </a>
    
    <a style="display:none;" id="J_leix_2" class="weui-cell weui-cell_access" href="/userPage/user_role/2">    <!--2员工、3合伙人-->
        <div class="weui-cell__hd tbs"><i class="icon-label"></i></div>
        <div class="weui-cell__bd">
            <p>类型</p>
        </div>
    </a>
    
    <a style="display:none;" id="J_leix_3" class="weui-cell weui-cell_access" href="/userPage/user_role/3">    <!--2员工、3合伙人-->
        <div class="weui-cell__hd tbs"><i class="icon-label"></i></div>
        <div class="weui-cell__bd">
            <p>类型</p>
        </div>
    </a>
    
    <a style="display:none;" id="J_fenz" class="weui-cell weui-cell_access" href="/userPage/group_edit">
        <div class="weui-cell__hd tbs"><i class="icon-folder"></i></div>
        <div class="weui-cell__bd">
            <p>分组</p>
        </div>
    </a>
</div>

<div class="weui-cells no_jt" id="J_userList">
    
</div>

<div class="weui-loadmore" id="J_loadmore" style="display:none;">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>

<a style="margin:10px 0 20px; display:block; color:#8b8b8b; font-size:17px; line-height:40px; text-align:center" href="javascript:;" id="J_qieh" data-num="0">切换到类型列表</a>

<script src="/js/zepto.min.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="/js/comm.js"></script>
<script type="text/javascript">
//类型数据
function leix_List(id){
	var uid = "${uid}";
	var data = {uid:uid,id:id,rows:1000};   //id 2,员工  3,合伙人
	var url = "/role/getRole";
	
	$('#J_loadmore').show();
	
	$.ajax({
		type: "POST",
		dataType: 'json',
		async: false,
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(data),
		url: url,
		success: function(res){
			if(res.code == 200){
				var list = res.data.list;
				for (var i =0;i<list.length;i++){
					var shtml = '<a class="weui-cell weui-cell_access" href="/userPage/role_user/'+list[i]['id']+'">'+
									'<div class="weui-cell__hd tbs"><i class="icon-label"></i></div>'+
									'<div class="weui-cell__bd">'+
										'<p>'+list[i]['name']+'</p>'+
									'</div>'+
									'<div class="weui-cell__ft">'+list[i]["total"]+'</div>'+
								'</a>'
					if(list[i]['id'] == 0){
						$('#J_userList').prepend(shtml)
					}else{
						$('#J_userList').append(shtml)
					}
				}

			}else{
				weui.topTips(res.msg);
			}
		},
		error: function(e){

		},
		complete: function(e){
			$('#J_loadmore').hide();
		}
	});
	
}

//分组数据
function fenz_List(){
	var uid = "${uid}";
	var data = {uid:uid,id:1,rows:1000};   //id 1,员工  2,合伙人(暂没有分组)
	var url = "/group/group_user";
	
	$('#J_loadmore').show();
	
	$.ajax({
		type: "POST",
		dataType: 'json',
		async: false,
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(data),
		url: url,
		success: function(res){
			if(res.code == 200){
				var list = res.data.list;
				for (var i =0;i<list.length;i++){
					var shtml = '<a class="weui-cell weui-cell_access" href="/userPage/group_set/'+list[i]['id']+'">'+
									'<div class="weui-cell__hd tbs"><i class="icon-folder"></i></div>'+
									'<div class="weui-cell__bd">'+
										'<p>'+list[i]['name']+'</p>'+
									'</div>'+
									'<div class="weui-cell__ft">'+list[i]["total"]+'</div>'+
								'</a>'
					if(list[i]['id'] == 0){
						$('#J_userList').prepend(shtml)
					}else{
						$('#J_userList').append(shtml)
					}
				}

			}else{
				weui.topTips(res.msg);
			}
		},
		error: function(e){

		},
		complete: function(e){
			$('#J_loadmore').hide();
		}
	});
	
}

$(function(){	
	//类型判断
	if('${id}' == 2){			//2员工 3合伙人
		$('#J_tianj').show()
		$('#J_leix_2').show()
		$('#J_leix_3').hide()
		$('#J_fenz').show()
		
		fenz_List()				//加载分组
	}else{
		$('title').html('合伙人管理')
		$('#J_tianj').remove()
		$('#J_leix_2').remove()
		$('#J_leix_3').show()
		$('#J_fenz').hide()
		$('#J_qieh').remove()
		
		leix_List(3)			//加载类型,2员工 3合伙人
	}
	//---------------------------
	//切换列表
	$(document).on('click','#J_qieh',function(){
		var $this_t = $(this)
		var num = $this_t.attr('data-num')
		
		if(num == 0){
			$this_t.attr('data-num',1)
			$('#J_qieh').html('切换到分组列表')
			$('#J_userList').html('')
			leix_List(2)	//切换到类型
		}else if(num == 1){
			$this_t.attr('data-num',0)
			$('#J_qieh').html('切换到类型列表')
			$('#J_userList').html('')
			fenz_List()		//切换到分组
		}	
	})
	//---------------------------
	//搜索
	weui.searchBar('#searchBar');
});
</script>
</body>
</html>
